//
//  KFSingleAlertView.m
//  KafeeSale
//
//  Created by Liboom on 2025/7/4.
//

#import "KFSingleAlertView.h"
@interface KFSingleAlertView()
@property(nonatomic, strong) UILabel *msgLab;
@end
@implementation KFSingleAlertView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
        [self createUI];
    }
    return self;
}
-(void)createUI{
    UIView * bgView = [UIView new];
    bgView.cornerRadius = 10;
    bgView.backgroundColor = UIColor.whiteColor;
    [self addSubview:bgView];
    bgView.sd_layout.centerXEqualToView(self).centerYEqualToView(self).widthIs(300).heightIs(190);
    UILabel * lab = [UILabel labelWithTitle:@"提示" color:UIColor.blackColor fontSize:17];
    [bgView addSubview:lab];
    lab.sd_layout.leftSpaceToView(bgView, 15).topSpaceToView(bgView, 15).heightIs(20);
    [lab setSingleLineAutoResizeWithMaxWidth:300];
    
    self.msgLab = [UILabel labelWithTitle:@"" color:UIColor.blackColor fontSize:15 alignment:NSTextAlignmentLeft];
    [bgView addSubview:self.msgLab];
    self.msgLab.sd_layout.leftSpaceToView(bgView, 15).rightSpaceToView(bgView, 15).centerYEqualToView(bgView).offset(-30).autoHeightRatio(0);
    // --- 添加底部分隔线和按钮 ---
    // 1. 按钮上方分隔线
    UIView *topLine = [UIView new];
    topLine.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0]; // 浅灰色
    [bgView addSubview:topLine];
    topLine.sd_layout.leftSpaceToView(bgView, 0).rightSpaceToView(bgView, 0)
          .bottomSpaceToView(bgView, 45) // 在输入框下方预留空间
          .heightIs(0.5); // 0.5pt细线

    // 2. 垂直分隔线（按钮之间）
    UIView *verticalLine = [UIView new];
    verticalLine.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
    [bgView addSubview:verticalLine];
    verticalLine.sd_layout.centerXEqualToView(bgView).topSpaceToView(topLine, 0)
               .widthIs(0.5).heightIs(45);

    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [confirmBtn setTitleColor:[UIColor colorWithRed:0.15 green:0.61 blue:1 alpha:1] forState:UIControlStateNormal];
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [confirmBtn addTarget:self action:@selector(certainBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:confirmBtn];
    confirmBtn.sd_layout.leftSpaceToView(bgView, 0).topSpaceToView(topLine, 0)
        .rightSpaceToView(verticalLine, 0).heightIs(45);
    // 3. 创建按钮
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:cancelBtn];
    cancelBtn.sd_layout.leftSpaceToView(verticalLine, 0).topSpaceToView(topLine, 0)
        .rightSpaceToView(bgView, 0).heightIs(45);

    
}
- (void)setMsgString:(NSString *)msgString{
    self.msgLab.text = msgString;
}
-(void)cancelBtnClick{
    self.actionBlock(0);
}
-(void)certainBtnClick{
    self.actionBlock(1);
}
@end
